package com.engine.budget.web;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.engine.budget.enums.VerifyMessage;
import com.engine.budget.service.BusinessBudgetService;
import com.engine.budget.service.impl.BusinessBudgetServiceImpl;
import com.engine.budget.util.VerifyUtil;
import com.engine.common.util.ServiceUtil;
import weaver.conn.RecordSet;
import weaver.general.Util;
import weaver.hrm.User;
import weaver.integration.logging.Logger;
import weaver.integration.logging.LoggerFactory;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;


/**
 * @author DY
 * @date 2024/7/8 10:01
 * @description: 预算模块外部系统调用接口
 * @version 1.0
 */
public class BusinessBudgetWeb {

    private BusinessBudgetService getService() {
        return ServiceUtil.getService(BusinessBudgetServiceImpl.class);
    }

    private BusinessBudgetService getServiceByUser(User user) {
        return ServiceUtil.getService(BusinessBudgetServiceImpl.class, user);
    }

    private Logger logger = LoggerFactory.getLogger(this.getClass());

    /**
     * 预算执行指令接口
     * @param request
     * @param response
     * @return
     */
    @POST
    @Path("/execbudget")
    @Produces({MediaType.APPLICATION_JSON})
    public String execBudget(@Context HttpServletRequest request, @Context HttpServletResponse response,
                                       String params){
        //请求唯一编号
        UUID logId = UUID.randomUUID();
        Map<String, Object> result = new HashMap();
        result.put("logId", logId);
        try {
            logger.info("外部系统调用预算执行指令接口start...LogID:"+logId+", params: "+params);
            params = Util.null2String(params);
            if("".equals(params)) {
                Map<String, Object> errMap = VerifyMessage.CRCS_EMPTY.fromMap();
                errMap.put("status", -1);
                result.put("result", "[]");
                result.putAll(errMap);
                return JSONObject.toJSONString(result);
            }
            JSONObject paramObj = JSONObject.parseObject(params);
            JSONObject otherMap = new JSONObject();
            otherMap.put("request", request);
            otherMap.put("logId", logId);

            //接口参数安全验证
            boolean b = VerifyUtil.verifyTicket(paramObj);
            if(!b) {
                Map<String, Object> errMap = VerifyMessage.SAFE_ERR.fromMap();
                errMap.put("status", -3);
                result.put("result", "[]");
                result.putAll(errMap);
                return JSONObject.toJSONString(result);
            }
            JSONObject safetyObj = paramObj.getJSONObject("safety");
            String useraccount = Util.null2String(safetyObj.getString("useraccount"));

            User user = VerifyUtil.getUserByCode(useraccount, new RecordSet());
            if(user == null) {
                Map<String, Object> errMap = VerifyMessage.YWYZ_ERR
                        .setErrorMessage("【useraccount_操作人账号】未匹配到对应人员").fromMap();
                errMap.put("status", -3);
                result.put("result", "[]");
                result.putAll(errMap);
                return JSONObject.toJSONString(result);
            }

            result = getServiceByUser(user).execBudget(paramObj, otherMap);
            logger.info("外部系统调用预算执行指令接口end...LogID:"+logId+", result: "+result);
        } catch (Exception e) {
            logger.info("外部系统调用预算执行指令接口异常...LogID:"+logId+", err: "+e.getMessage(), e);
            Map<String, Object> errMap = VerifyMessage.XT_ERR.fromMap();
            errMap.put("status", -3);
            result.put("result", "[]");
            result.putAll(errMap);
        }
        return JSONObject.toJSONString(result);
    }


    /**
     * 预算仅执行指令
     * @param request
     * @param response
     * @return
     */
    @POST
    @Path("/onlyExecBudget")
    @Produces({MediaType.APPLICATION_JSON})
    public String onlyExecBudget(@Context HttpServletRequest request, @Context HttpServletResponse response,
                             String params){

        //请求唯一编号
        UUID logId = UUID.randomUUID();
        Map<String, Object> result = new HashMap();
        result.put("logId", logId);
        try {
            logger.info("外部系统调用预算预算仅执行指令接口start...LogID:"+logId+", params: "+params);
            params = Util.null2String(params);
            if("".equals(params)) {
                Map<String, Object> errMap = VerifyMessage.CRCS_EMPTY.fromMap();
                errMap.put("status", -1);
                result.put("result", "[]");
                result.putAll(errMap);
                return JSONObject.toJSONString(result);
            }
            JSONObject paramObj = JSONObject.parseObject(params);
            JSONObject otherMap = new JSONObject();
            otherMap.put("request", request);
            otherMap.put("logId", logId);

            //接口参数安全验证
            boolean b = VerifyUtil.verifyTicket(paramObj);
            if(!b) {
                Map<String, Object> errMap = VerifyMessage.SAFE_ERR.fromMap();
                errMap.put("status", -3);
                result.put("result", "[]");
                result.putAll(errMap);
                return JSONObject.toJSONString(result);
            }

            result = getService().onlyExecBudget(paramObj, otherMap);
            logger.info("外部系统调用预算预算仅执行指令接口end...LogID:"+logId+", result: "+result);
        } catch (Exception e) {
            logger.info("外部系统调用预算预算仅执行指令接口异常...LogID:"+logId+", err: "+e.getMessage(), e);
            Map<String, Object> errMap = VerifyMessage.XT_ERR.fromMap();
            errMap.put("status", -3);
            result.put("result", "[]");
            result.putAll(errMap);
        }
        return JSONObject.toJSONString(result);
    }


    /**
     * 预算校验指令接口
     * @param request
     * @param response
     * @return
     */
    @POST
    @Path("/verify")
    @Produces({MediaType.APPLICATION_JSON})
    public String verify(@Context HttpServletRequest request, @Context HttpServletResponse response,
                             String params){

        //请求唯一编号
        UUID logId = UUID.randomUUID();
        Map<String, Object> result = new HashMap();
        result.put("logId", logId);
        try {
            logger.info("外部系统调用预算校验指令接口start...LogID:"+logId+", params: "+params);
            params = Util.null2String(params);
            if("".equals(params)) {
                Map<String, Object> errMap = VerifyMessage.CRCS_EMPTY.fromMap();
                errMap.put("status", -1);
                result.put("result", "[]");
                result.putAll(errMap);
                return JSONObject.toJSONString(result);
            }
            JSONObject paramObj = JSONObject.parseObject(params);
            JSONObject otherMap = new JSONObject();
            otherMap.put("request", request);
            otherMap.put("logId", logId);

            //接口参数安全验证
            boolean b = VerifyUtil.verifyTicket(paramObj);
            if(!b) {
                Map<String, Object> errMap = VerifyMessage.SAFE_ERR.fromMap();
                errMap.put("status", -3);
                result.put("result", "[]");
                result.putAll(errMap);
                return JSONObject.toJSONString(result);
            }
            JSONObject safetyObj = paramObj.getJSONObject("safety");
            String useraccount = Util.null2String(safetyObj.getString("useraccount"));

            User user = VerifyUtil.getUserByCode(useraccount, new RecordSet());
            if(user == null) {
                Map<String, Object> errMap = VerifyMessage.YWYZ_ERR
                        .setErrorMessage("【useraccount_操作人账号】未匹配到对应人员").fromMap();
                errMap.put("status", -3);
                result.put("result", "[]");
                result.putAll(errMap);
                return JSONObject.toJSONString(result);
            }

            result = getServiceByUser(user).verify(paramObj, otherMap);
            logger.info("外部系统调用预算校验指令接口end...LogID:"+logId+", result: "+result);
        } catch (Exception e) {
            logger.info("外部系统调用预算校验指令接口异常...LogID:"+logId+", err: "+e.getMessage(), e);
            Map<String, Object> errMap = VerifyMessage.XT_ERR.fromMap();
            errMap.put("status", -3);
            result.put("result", "[]");
            result.putAll(errMap);
        }
        return JSONObject.toJSONString(result);
    }

    /**
     * 电商平台控制接口
     * @param request
     * @param response
     * @return
     */
    @POST
    @Path("/ecomplatctrl")
    @Produces({MediaType.APPLICATION_JSON})
    public String ecomPlatCtrl(@Context HttpServletRequest request, @Context HttpServletResponse response,
                             String params){

        //请求唯一编号
        UUID logId = UUID.randomUUID();
        Map<String, Object> result = new HashMap();
        result.put("logId", logId);
        try {
            logger.info("外部系统调用电商平台控制接口start...LogID:"+logId+", params: "+params);
            params = Util.null2String(params);
            if("".equals(params)) {
                Map<String, Object> errMap = VerifyMessage.CRCS_EMPTY.fromMap();
                errMap.put("status", -1);
                result.put("result", "[]");
                result.putAll(errMap);
                return JSONObject.toJSONString(result);
            }
            JSONObject paramObj = JSONObject.parseObject(params);
            JSONObject otherMap = new JSONObject();
            otherMap.put("request", request);
            otherMap.put("logId", logId);

            //接口参数安全验证
            boolean b = VerifyUtil.verifyTicket(paramObj);
            if(!b) {
                Map<String, Object> errMap = VerifyMessage.SAFE_ERR.fromMap();
                errMap.put("status", -3);
                result.put("doc", "[]");
                result.putAll(errMap);
                return JSONObject.toJSONString(result);
            }
            JSONObject safetyObj = paramObj.getJSONObject("safety");
            String useraccount = Util.null2String(safetyObj.getString("useraccount"));

            User user = VerifyUtil.getUserByCode(useraccount, new RecordSet());
            if(user == null) {
                Map<String, Object> errMap = VerifyMessage.YWYZ_ERR
                        .setErrorMessage("【useraccount_操作人账号】未匹配到对应人员").fromMap();
                errMap.put("status", -3);
                result.put("doc", "[]");
                result.putAll(errMap);
                return JSONObject.toJSONString(result);
            }

            result = getServiceByUser(user).ecomPlatCtrl(paramObj, otherMap);
            logger.info("外部系统调用电商平台控制接口end...LogID:"+logId+", result: "+result);
        } catch (Exception e) {
            logger.info("外部系统调用电商平台控制接口异常...LogID:"+logId+", err: "+e.getMessage(), e);
            Map<String, Object> errMap = VerifyMessage.XT_ERR.fromMap();
            errMap.put("status", -3);
            result.put("doc", "[]");
            result.putAll(errMap);
        }
        return JSONObject.toJSONString(result);
    }

    /**
     * 预算项目底表查询接口
     * @param request
     * @param response
     * @return
     */
    @POST
    @Path("/queryItem")
    @Produces({MediaType.APPLICATION_JSON})
    public String queryItem(@Context HttpServletRequest request, @Context HttpServletResponse response, String params){
        Map<String, Object> apidatas = new HashMap<String, Object>();
        //请求唯一编号
        UUID logId = UUID.randomUUID();
        apidatas.put("logId", logId);
        try {
            logger.info("预算项目底表查询接口start...LogID:"+logId+", params: "+params);
            params = Util.null2String(params);
            if("".equals(params)) {
                Map<String, Object> errMap = VerifyMessage.CRCS_EMPTY.fromMap();
                errMap.put("status", -1);
                apidatas.putAll(errMap);
                return JSONObject.toJSONString(apidatas);
            }
            JSONObject paramObj = JSONObject.parseObject(params);
            JSONObject otherMap = new JSONObject();
            otherMap.put("request", request);
            otherMap.put("logId", logId);

            //接口参数安全验证
            boolean b = VerifyUtil.verifyTicket(paramObj);
            if(!b) {
                Map<String, Object> errMap = VerifyMessage.SAFE_ERR.fromMap();
                errMap.put("status", -3);
                apidatas.putAll(errMap);
                return JSONObject.toJSONString(apidatas);
            }
            JSONObject map = paramObj.getJSONObject("params");

            apidatas.putAll(getService().queryItem(map));
            apidatas.put("status", "0");
            Map<String, Object> errMap = VerifyMessage.SUCCESS.fromMap();
            apidatas.putAll(errMap);
        } catch (Exception e) {
            logger.info("预算项目底表查询接口异常...LogID:"+logId+", err: "+e.getMessage(), e);
            Map<String, Object> errMap = VerifyMessage.XT_ERR.fromMap();
            errMap.put("status", -3);
            apidatas.putAll(errMap);
        }

        logger.info("预算项目底表查询接口end...LogID:"+logId+", result: "+apidatas);
        return JSONObject.toJSONString(apidatas);
    }

    /**
     * 预算事项底表查询接口
     * @param request
     * @param response
     * @return
     */
    @POST
    @Path("/queryEvent")
    @Produces({MediaType.APPLICATION_JSON})
    public String queryEvent(@Context HttpServletRequest request, @Context HttpServletResponse response, String params){
        Map<String, Object> apidatas = new HashMap<String, Object>();
        //请求唯一编号
        UUID logId = UUID.randomUUID();
        apidatas.put("logId", logId);
        try {
            logger.info("预算事项底表查询接口start...LogID:"+logId+", params: "+params);
            params = Util.null2String(params);
            if("".equals(params)) {
                Map<String, Object> errMap = VerifyMessage.CRCS_EMPTY.fromMap();
                errMap.put("status", -1);
                apidatas.putAll(errMap);
                return JSONObject.toJSONString(apidatas);
            }
            JSONObject paramObj = JSONObject.parseObject(params);
            JSONObject otherMap = new JSONObject();
            otherMap.put("request", request);
            otherMap.put("logId", logId);

            //接口参数安全验证
            boolean b = VerifyUtil.verifyTicket(paramObj);
            if(!b) {
                Map<String, Object> errMap = VerifyMessage.SAFE_ERR.fromMap();
                errMap.put("status", -3);
                apidatas.putAll(errMap);
                return JSONObject.toJSONString(apidatas);
            }
            JSONObject map = paramObj.getJSONObject("params");

            apidatas.putAll(getService().queryEvent(map));
            apidatas.put("status", "0");
            Map<String, Object> errMap = VerifyMessage.SUCCESS.fromMap();
            apidatas.putAll(errMap);
        } catch (Exception e) {
            logger.info("预算事项底表查询接口异常...LogID:"+logId+", err: "+e.getMessage(), e);
            Map<String, Object> errMap = VerifyMessage.XT_ERR.fromMap();
            errMap.put("status", -3);
            apidatas.putAll(errMap);
        }

        logger.info("预算事项底表查询接口end...LogID:"+logId+", result: "+apidatas);
        return JSONObject.toJSONString(apidatas);
    }



    /**
     * 预算占用表查询接口
     * @param request
     * @param response
     * @return
     */
    @POST
    @Path("/queryOccupy")
    @Produces({MediaType.APPLICATION_JSON})
    public String queryOccupy(@Context HttpServletRequest request, @Context HttpServletResponse response, String params){
        Map<String, Object> apidatas = new HashMap<String, Object>();
        //请求唯一编号
        UUID logId = UUID.randomUUID();
        apidatas.put("logId", logId);
        try {
            logger.info("预算占用表查询接口start...LogID:"+logId+", params: "+params);
            params = Util.null2String(params);
            if("".equals(params)) {
                Map<String, Object> errMap = VerifyMessage.CRCS_EMPTY.fromMap();
                errMap.put("status", -1);
                apidatas.putAll(errMap);
                return JSONObject.toJSONString(apidatas);
            }
            JSONObject paramObj = JSONObject.parseObject(params);
            JSONObject otherMap = new JSONObject();
            otherMap.put("request", request);
            otherMap.put("logId", logId);

            //接口参数安全验证
            boolean b = VerifyUtil.verifyTicket(paramObj);
            if(!b) {
                Map<String, Object> errMap = VerifyMessage.SAFE_ERR.fromMap();
                errMap.put("status", -3);
                apidatas.putAll(errMap);
                return JSONObject.toJSONString(apidatas);
            }
            JSONObject map = paramObj.getJSONObject("params");

            apidatas.putAll(getService().queryOccupy(map));
            apidatas.put("status", "0");
            Map<String, Object> errMap = VerifyMessage.SUCCESS.fromMap();
            apidatas.putAll(errMap);
        } catch (Exception e) {
            logger.info("预算占用表查询接口异常...LogID:"+logId+", err: "+e.getMessage(), e);
            Map<String, Object> errMap = VerifyMessage.XT_ERR.fromMap();
            errMap.put("status", -3);
            apidatas.putAll(errMap);
        }

        logger.info("预算占用表查询接口end...LogID:"+logId+", result: "+apidatas);
        return JSONObject.toJSONString(apidatas);
    }

    /**
     * 预算执行底表查询接口
     * @param request
     * @param response
     * @return
     */
    @POST
    @Path("/queryExec")
    @Produces({MediaType.APPLICATION_JSON})
    public String queryExec(@Context HttpServletRequest request, @Context HttpServletResponse response, String params){
        Map<String, Object> apidatas = new HashMap<String, Object>();
        //请求唯一编号
        UUID logId = UUID.randomUUID();
        apidatas.put("logId", logId);
        try {
            logger.info("预算执行底表查询接口start...LogID:"+logId+", params: "+params);
            params = Util.null2String(params);
            if("".equals(params)) {
                Map<String, Object> errMap = VerifyMessage.CRCS_EMPTY.fromMap();
                errMap.put("status", -1);
                apidatas.putAll(errMap);
                return JSONObject.toJSONString(apidatas);
            }
            JSONObject paramObj = JSONObject.parseObject(params);
            JSONObject otherMap = new JSONObject();
            otherMap.put("request", request);
            otherMap.put("logId", logId);

            //接口参数安全验证
            boolean b = VerifyUtil.verifyTicket(paramObj);
            if(!b) {
                Map<String, Object> errMap = VerifyMessage.SAFE_ERR.fromMap();
                errMap.put("status", -3);
                apidatas.putAll(errMap);
                return JSONObject.toJSONString(apidatas);
            }
            JSONObject map = paramObj.getJSONObject("params");

            apidatas.putAll(getService().queryExec(map));
            apidatas.put("status", "0");
            Map<String, Object> errMap = VerifyMessage.SUCCESS.fromMap();
            apidatas.putAll(errMap);
        } catch (Exception e) {
            logger.info("预算执行底表查询接口异常...LogID:"+logId+", err: "+e.getMessage(), e);
            Map<String, Object> errMap = VerifyMessage.XT_ERR.fromMap();
            errMap.put("status", -3);
            apidatas.putAll(errMap);
        }

        logger.info("预算执行底表查询接口end...LogID:"+logId+", result: "+apidatas);
        return JSONObject.toJSONString(apidatas);
    }

    /**
     * 获取weareport的数据
     * @param request
     * @param response
     * @return
     */
    @POST
    @Path("/project")
    @Produces({MediaType.APPLICATION_JSON})
    public String createWeaReportCondition(@Context HttpServletRequest request, @Context HttpServletResponse response,String params){

        Map<String, Object> apidatas = new HashMap<String, Object>();
        //请求唯一编号
        UUID logId = UUID.randomUUID();
        apidatas.put("logId", logId);
        try {
            logger.info("start...LogID:"+logId+", params: "+params);
            params = Util.null2String(params);
            if("".equals(params)) {
                Map<String, Object> errMap = VerifyMessage.CRCS_EMPTY.fromMap();
                errMap.put("status", -1);
                apidatas.putAll(errMap);
                return JSONObject.toJSONString(apidatas);
            }
            JSONObject paramObj = JSONObject.parseObject(params);
            JSONObject otherMap = new JSONObject();
            otherMap.put("request", request);
            otherMap.put("logId", logId);

            //接口参数安全验证
            boolean b = VerifyUtil.verifyTicket(paramObj);
            if(!b) {
                Map<String, Object> errMap = VerifyMessage.SAFE_ERR.fromMap();
                errMap.put("status", -3);
                apidatas.putAll(errMap);
                return JSONObject.toJSONString(apidatas);
            }
        return JSONObject.toJSONString(getService().createWeaReportCondition(JSONObject.parseObject(params, Map.class)));

        } catch (Exception e) {
            logger.info("创建流程异常...LogID:"+logId+", err: "+e.getMessage(), e);
            Map<String, Object> errMap = VerifyMessage.XT_ERR.fromMap();
            errMap.put("status", -3);
            apidatas.putAll(errMap);
        }

        logger.info("创建流程...LogID:"+logId+", result: "+apidatas);
        return JSONObject.toJSONString(apidatas);

    }

    /**
     * 预算项目底表查询接口_采购电商
     * @param request
     * @param response
     * @return
     */
    @POST
    @Path("/getBudgetBotTab")
    @Produces({MediaType.APPLICATION_JSON})
    public String getBudgetBotTab(@Context HttpServletRequest request, @Context HttpServletResponse response,String params){
        Map<String, Object> apidatas = new HashMap<String, Object>();
        //请求唯一编号
        UUID logId = UUID.randomUUID();
        apidatas.put("logId", logId);
        try {
            logger.info("预算项目底表查询接口_采购电商start...LogID:"+logId+", params: "+params);
            params = Util.null2String(params);
            if("".equals(params)) {
                Map<String, Object> errMap = VerifyMessage.CRCS_EMPTY.fromMap();
                errMap.put("status", -1);
                apidatas.putAll(errMap);
                return JSONObject.toJSONString(apidatas);
            }
            JSONObject paramObj = JSONObject.parseObject(params);
            JSONObject otherMap = new JSONObject();
            otherMap.put("request", request);
            otherMap.put("logId", logId);

            //接口参数安全验证
            boolean b = VerifyUtil.verifyTicket(paramObj);
            if(!b) {
                Map<String, Object> errMap = VerifyMessage.SAFE_ERR.fromMap();
                errMap.put("status", -3);
                apidatas.putAll(errMap);
                return JSONObject.toJSONString(apidatas);
            }
            //JSONObject map = paramObj.getJSONObject("params");
            JSONArray params1 = paramObj.getJSONArray("params");
            JSONObject map = JSONObject.parseObject(params1.get(0).toString());

            apidatas.putAll(getService().getBudgetBotTab(map));
            apidatas.put("status", "0");
            Map<String, Object> errMap = VerifyMessage.SUCCESS.fromMap();
            apidatas.putAll(errMap);
        } catch (Exception e) {
            logger.info("预算项目底表查询接口_采购电商异常...LogID:"+logId+", err: "+e.getMessage(), e);
            Map<String, Object> errMap = VerifyMessage.XT_ERR.fromMap();
            errMap.put("status", -3);
            apidatas.putAll(errMap);
        }

        logger.info("预算项目底表查询接口_采购电商end...LogID:"+logId+", result: "+apidatas);
        return JSONObject.toJSONString(apidatas);
    }

    /**
     * 重点工作查询接口
     * @param request
     * @param response
     * @return
     */
    @POST
    @Path("/getFocusWork")
    @Produces({MediaType.APPLICATION_JSON})
    public String getFocusWork(@Context HttpServletRequest request, @Context HttpServletResponse response,String params){
        Map<String, Object> apidatas = new HashMap<String, Object>();
        //请求唯一编号
        UUID logId = UUID.randomUUID();
        apidatas.put("logId", logId);
        try {
            logger.info("重点工作查询接口start...LogID:"+logId+", params: "+params);
            params = Util.null2String(params);
            if("".equals(params)) {
                Map<String, Object> errMap = VerifyMessage.CRCS_EMPTY.fromMap();
                errMap.put("status", -1);
                apidatas.putAll(errMap);
                return JSONObject.toJSONString(apidatas);
            }
            JSONObject paramObj = JSONObject.parseObject(params);
            JSONObject otherMap = new JSONObject();
            otherMap.put("request", request);
            otherMap.put("logId", logId);

            //接口参数安全验证
            boolean b = VerifyUtil.verifyTicket(paramObj);
            if(!b) {
                Map<String, Object> errMap = VerifyMessage.SAFE_ERR.fromMap();
                errMap.put("status", -3);
                apidatas.putAll(errMap);
                return JSONObject.toJSONString(apidatas);
            }
            //JSONObject map = paramObj.getJSONObject("params");
            JSONArray params1 = paramObj.getJSONArray("params");
            JSONObject map = JSONObject.parseObject(params1.get(0).toString());

            apidatas.putAll(getService().getFocusWork(map));
            apidatas.put("status", "0");
            Map<String, Object> errMap = VerifyMessage.SUCCESS.fromMap();
            apidatas.putAll(errMap);
        } catch (Exception e) {
            logger.info("重点工作查询接口异常...LogID:"+logId+", err: "+e.getMessage(), e);
            Map<String, Object> errMap = VerifyMessage.XT_ERR.fromMap();
            errMap.put("status", -3);
            apidatas.putAll(errMap);
        }

        logger.info("重点工作查询接口end...LogID:"+logId+", result: "+apidatas);
        return JSONObject.toJSONString(apidatas);
    }

    /**
     * 营销项目启动及调整接口
     * @param request
     * @param response
     * @return
     */
    @POST
    @Path("/marketProjectEnable")
    @Produces({MediaType.APPLICATION_JSON})
    public String marketProjectEnable(@Context HttpServletRequest request, @Context HttpServletResponse response, String params){
        Map<String, Object> apidatas = new HashMap<String, Object>();
        //请求唯一编号
        UUID logId = UUID.randomUUID();
        apidatas.put("logId", logId);
        try {
            logger.info("营销项目启动及调整接口start...LogID:"+logId+", params: "+params);
            params = Util.null2String(params);
            if("".equals(params)) {
                Map<String, Object> errMap = VerifyMessage.CRCS_EMPTY.fromMap();
                errMap.put("status", -1);
                apidatas.putAll(errMap);
                return JSONObject.toJSONString(apidatas);
            }
            JSONObject paramObj = JSONObject.parseObject(params);
            JSONObject otherMap = new JSONObject();
            otherMap.put("request", request);
            otherMap.put("logId", logId);

            //接口参数安全验证
            boolean b = VerifyUtil.verifyTicket(paramObj);
            if(!b) {
                Map<String, Object> errMap = VerifyMessage.SAFE_ERR.fromMap();
                errMap.put("status", -3);
                apidatas.putAll(errMap);
                return JSONObject.toJSONString(apidatas);
            }
            JSONObject map = paramObj.getJSONObject("params");
            JSONObject data = map.getJSONObject("data");
            String instruct = data.getString("instruct");
            if ("TZ".equals(instruct)||"TJ".equals(instruct)||"JY".equals(instruct)) {
                apidatas.putAll(getService().updateAdjustmentInterface(map));
            }else if ("QY".equals(instruct)||"XXTZ".equals(instruct)) {
                apidatas.putAll(getService().marketProjectEnable(map));
            }
            apidatas.put("status", "0");
            Map<String, Object> errMap = VerifyMessage.SUCCESS.fromMap();
            apidatas.putAll(errMap);
        } catch (Exception e) {
            logger.info("营销项目启动及调整接口...LogID:"+logId+", err: "+e.getMessage(), e);
            Map<String, Object> errMap = VerifyMessage.XT_ERR.fromMap();
            errMap.put("status", -3);
            apidatas.putAll(errMap);
        }

        logger.info("营销项目启动及调整接口end...LogID:"+logId+", result: "+apidatas);
        return JSONObject.toJSONString(apidatas);
    }



}
